package com.spring.sunflower.widget;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.lxj.xpopup.core.BottomPopupView;
import com.lxj.xpopup.util.XPopupUtils;
import com.spring.sunflower.R;
import com.spring.sunflower.bean.LabelBean;
import com.zyyoona7.picker.OptionsPickerView;
import com.zyyoona7.picker.ex.DayWheelView;
import com.zyyoona7.picker.ex.MonthWheelView;
import com.zyyoona7.picker.ex.YearWheelView;
import com.zyyoona7.picker.listener.OnOptionsSelectedListener;
import com.zyyoona7.wheel.WheelView;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * Created by Kevin on 2021/6/29<br/>
 * <p>
 * Describe:<br/>
 */
public class UserInfoBottomDialog extends BottomPopupView {
    private TextView tvOK, tvCancel, tvYear, tvMonth, tvDay;
    private YearWheelView yearWheelView;
    private MonthWheelView monthWheelView;
    private DayWheelView dayWheelView;
    private OnBottomSelectListener listener;
    private OptionsPickerView optionsPickerView;
    private List<String> data;
    private List<LabelBean.DatasBean> dataX;

    public UserInfoBottomDialog(@NonNull @NotNull Context context, List<String> data, OnBottomSelectListener listener) {
        super(context);
        this.listener = listener;
        this.data = data;
    }

    public UserInfoBottomDialog(@NonNull @NotNull Context context, OnBottomSelectListener listener, List<LabelBean.DatasBean> data) {
        super(context);
        this.listener = listener;
        this.dataX = data;
    }


    @Override
    protected int getImplLayoutId() {
        return R.layout.custom_bottom_dialog;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        tvOK = findViewById(R.id.tvOK);
        tvCancel = findViewById(R.id.tvCancel);
        optionsPickerView = findViewById(R.id.optionPicker);
        optionsPickerView.setTextSize(24, true);
        optionsPickerView.setCurvedArcDirection(WheelView.CURVED_ARC_DIRECTION_CENTER);
        optionsPickerView.setCurvedArcDirectionFactor(0.3f);
        optionsPickerView.setData(data);
        optionsPickerView.setVisibleItems(7);
        optionsPickerView.setOpt1SelectedPosition(20);
        optionsPickerView.setOnOptionsSelectedListener(new OnOptionsSelectedListener<String>() {

            @Override
            public void onOptionsSelected(int i, @Nullable String s, int i1, @Nullable String t1, int i2, @Nullable String t2) {
                if (listener != null) {
//                    listener.onBottomSelect(String.valueOf(i), s);
                }
            }
        });
        tvOK.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                String opt1SelectedData = (String) optionsPickerView.getOpt1SelectedData();
                int opt1SelectedPosition = optionsPickerView.getOpt1SelectedPosition();
                if (listener != null) {
                    listener.onBottomSelect(String.valueOf(opt1SelectedPosition), opt1SelectedData);
                }
                dismiss();
            }
        });
        tvCancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

    }

    @Override
    protected int getMaxHeight() {
        return (int) (XPopupUtils.getScreenHeight(getContext()) * 0.5f);
    }

//    @Override
//    public int getMinimumHeight() {
//        return (int) (XPopupUtils.getScreenHeight(getContext()) * 0.3f);
//    }


}
